package org.spring.springboot.service.impl;


import org.spring.springboot.domain.ShareFile;
import org.spring.springboot.domain.GraphFile;
import org.spring.springboot.service.IShareFileSvc;
import org.spring.springboot.dao.ShareFileDao;
import org.spring.springboot.dao.GraphFileDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ShareFileSvc implements IShareFileSvc {
    @Autowired
    private ShareFileDao dao;

    @Autowired
    private GraphFileDao graphFileDao;

    public List<GraphFile> selectAll(String userid) {
        List<ShareFile> shareInfoList = dao.selectAll(userid);
        List<GraphFile> shareFileList = new ArrayList<GraphFile>();
        for (ShareFile info : shareInfoList) {
            GraphFile file = graphFileDao.selectOne(info.getGid());
            if (file != null){
                shareFileList.add(file);
            }
        }
        return shareFileList;
    }

    public void save(ShareFile info) {
        dao.save(info);
    }

    public void delete(String gid, String userid) {
        dao.delete(gid, userid);
    }
}
